ECHO:/*      $OpenBSD: busop_c.in,v 1.2 2010/04/04 12:49:30 miod Exp $   */
ECHO:
ECHO:/*
ECHO: * Copyright (c) 2003 Henric Jungheim
ECHO: * All rights reserved.
ECHO: *
ECHO: * Redistribution and use in source and binary forms, with or without
ECHO: * modification, are permitted provided that the following conditions
ECHO: * are met:
ECHO: * 1. Redistributions of source code must retain the above copyright
ECHO: *    notice, this list of conditions and the following disclaimer.
ECHO: * 2. Redistributions in binary form must reproduce the above copyright
ECHO: *    notice, this list of conditions and the following disclaimer in the
ECHO: *    documentation and/or other materials provided with the distribution.
ECHO: * 3. The name of the author may not be used to endorse or promote products
ECHO: *    derived from this software without specific prior written permission.
ECHO: *
ECHO: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
ECHO: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
ECHO: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
ECHO: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
ECHO: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
ECHO: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
ECHO: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
ECHO: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
ECHO: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
ECHO: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ECHO: */
ECHO:
ECHO:#include <sys/param.h>
ECHO:#include <sys/systm.h>
ECHO:#include <sys/kernel.h>
ECHO:
ECHO:#include <machine/bus.h>
ECHO:

void
bus_space_read_<RAW>multi_<NUM>(bus_space_tag_t t, bus_space_handle_t h,
    bus_size_t o,
NRAW:    <TYPE> *a, bus_size_t c)
RAW:    void *a, size_t c)
{
	<TYPE> *p = a;

	BUS_SPACE_ASSERT(t, h, o, <NUM>);
	BUS_SPACE_TRACE(t, h,
	    ("bsrm<NUM>(%llx + %llx, %x, %x) ->", (long long)h.bh_ptr,
	    (long long)o, t-><ASI>, c));
RAW:	c /= sizeof(<TYPE>);

	++c;  /* Looping on "--c" is slightly faster than on "c--" */
	asi_set(t-><ASI>);
	while (--c > 0) {
		<TYPE> r = <LOAD>_asi(h.bh_ptr + o);
		BUS_SPACE_TRACE(t, h, (" <FMT>", r));
		*p++ = r;
	}

	BUS_SPACE_TRACE(t, h, ("\n"));
}

void
bus_space_write_<RAW>multi_<NUM>(bus_space_tag_t t, bus_space_handle_t h,
    bus_size_t o,
NRAW:    const <TYPE> *a, bus_size_t c)
RAW:    const void *a, size_t c)
{
	const <TYPE> *p = a;

	BUS_SPACE_ASSERT(t, h, o, <NUM>);
	BUS_SPACE_TRACE(t, h,
	    ("bswm<NUM>(%llx + %llx, %x, %x) <-", (long long)h.bh_ptr,
	    (long long)o, t-><ASI>, c));
RAW:	c /= sizeof(<TYPE>);

	++c;  /* Looping on "--c" is slightly faster than on "c--" */
	asi_set(t-><ASI>);
	while (--c > 0) {
		<TYPE> r = *p++;
		BUS_SPACE_TRACE(t, h, (" <FMT>", r));
		<STORE>_asi(h.bh_ptr + o, r);
	}

	BUS_SPACE_TRACE(t, h, ("\n"));
}

void
bus_space_set_<RAW>multi_<NUM>(bus_space_tag_t t, bus_space_handle_t h,
    bus_size_t o, <TYPE> v,
NRAW:    bus_size_t c)
RAW:    size_t c)
{
	BUS_SPACE_ASSERT(t, h, o, <NUM>);
	BUS_SPACE_TRACE(t, h,
	    ("bssm<NUM>(%llx + %llx, %x, %x) <- <FMT>\n", (long long)h.bh_ptr,
	    (long long)o, t-><ASI>, c, v));
RAW:	c /= sizeof(<TYPE>);

	++c;  /* Looping on "--c" is slightly faster than on "c--" */
	asi_set(t-><ASI>);
	while (--c > 0)
		<STORE>_asi(h.bh_ptr + o, v);
}

void
bus_space_read_<RAW>region_<NUM>(bus_space_tag_t t, bus_space_handle_t h,
    bus_size_t o,
NRAW:    <TYPE> *a, bus_size_t c)
RAW:    void *a, size_t c)
{
	<TYPE> *p = a;
	paddr_t ptr = h.bh_ptr + o;

	BUS_SPACE_ASSERT(t, h, o, <NUM>);
	BUS_SPACE_TRACE(t, h,
	    ("bsrr<NUM>(%llx + %llx, %x, %x) <- \n", (long long)h.bh_ptr,
	    (long long)o, t-><ASI>, c));
RAW:	c /= sizeof(<TYPE>);

	asi_set(t-><ASI>);
	for (; c; p++, c--, ptr += <NUM>) {
		<TYPE> r = <LOAD>_asi(ptr);
		BUS_SPACE_TRACE(t, h, (" <FMT>", r));
		*p = r;
	}

	BUS_SPACE_TRACE(t, h, ("\n"));
}

void
bus_space_write_<RAW>region_<NUM>(bus_space_tag_t t, bus_space_handle_t h,
    bus_size_t o,
NRAW:    const <TYPE> *a, bus_size_t c)
RAW:    const void *a, size_t c)
{
	const <TYPE> *p = a;
	paddr_t ptr = h.bh_ptr + o;

	BUS_SPACE_ASSERT(t, h, o, <NUM>);
	BUS_SPACE_TRACE(t, h,
	    ("bswr<NUM>(%llx + %llx, %x, %x) <-", (long long)h.bh_ptr,
	    (long long)o, t-><ASI>, c));
RAW:	c /= sizeof(<TYPE>);

	asi_set(t-><ASI>);
	for (; c; p++, c--, ptr += <NUM>) {
		<TYPE> r = *p;
		BUS_SPACE_TRACE(t, h, (" <FMT>", r));
		<STORE>_asi(ptr, r);
	}

	BUS_SPACE_TRACE(t, h, ("\n"));
}

void
bus_space_set_<RAW>region_<NUM>(bus_space_tag_t t, bus_space_handle_t h,
    bus_size_t o, <TYPE> v,
NRAW:    bus_size_t c)
RAW:    size_t c)
{
	paddr_t ptr = h.bh_ptr + o;

	BUS_SPACE_ASSERT(t, h, o, <NUM>);
	BUS_SPACE_TRACE(t, h,
	    ("bssr<NUM>(%llx + %llx, %x, %x) <- <FMT>\n", (long long)h.bh_ptr,
	    (long long)o, t-><ASI>, c, v));
RAW:	c /= sizeof(<TYPE>);

	asi_set(t-><ASI>);
	for (; c; c--, ptr += <NUM>)
		<STORE>_asi(ptr, v);
}

NRAW:void
NRAW:bus_space_copy_<RAW><NUM>(bus_space_tag_t t, bus_space_handle_t h1,
NRAW:    bus_size_t o1, bus_space_handle_t h2, bus_size_t o2,
NRAW:    bus_size_t c)
NRAW:{
NRAW:	paddr_t ptr1 = h1.bh_ptr + o1;
NRAW:	paddr_t ptr2 = h2.bh_ptr + o2;
NRAW:
NRAW:	BUS_SPACE_ASSERT(t, h1, o2, <NUM>);
NRAW:	BUS_SPACE_ASSERT(t, h2, o2, <NUM>);
NRAW:	BUS_SPACE_TRACE(t, h1,
NRAW:	    ("bscr<NUM>(%llx + %llx, %llx + %llx, %x, %x) <-> \n",
NRAW:	    (long long)h1.bh_ptr, (long long)o1,
NRAW:	    (long long)h2.bh_ptr, (long long)o2,
NRAW:	    t-><ASI>, c));
NRAW:
NRAW:	asi_set(t-><ASI>);
NRAW:	for (; c; c--, ptr1 += <NUM>, ptr2 += <NUM>) {
NRAW:		<TYPE> r = <LOAD>_asi(ptr2);
NRAW:		BUS_SPACE_TRACE(t, h1, (" <FMT>", r));
NRAW:		<STORE>_asi(ptr1, r);
NRAW:	}
NRAW:	BUS_SPACE_TRACE(t, h1, ("\n"));
NRAW:}

